package com.max.xihu.patterns.proxy.common;

/**
 * @Author: Max
 * @Date: 2020-09-10 22:45
 * @Description:
 */
public class Coder implements IUser{

    private String name;
    private IUser proxy;

    public Coder(String name){
          this.name = name;
    }

    @Override
    public IUser getProxy() {
        this.proxy = new CoderProxy(this);
        return this.proxy;
    }

    @Override
    public void eat() {
        if (this.isProxy()){
            System.out.println(name+":吃饭");
        }else {
            System.out.println("无指定代理");
        }

    }

    @Override
    public void work() {
        if (this.isProxy()){
            System.out.println(name+":工作");
        }else {
            System.out.println("无指定代理");
        }

    }

    @Override
    public void sleep() {
        if (this.isProxy()){
            System.out.println(name+":睡觉");
        }else {
            System.out.println("无指定代理");
        }

    }

    private boolean isProxy(){
        if (this.proxy == null){
            return false;
        }
        return true;
    }
}
